package com.klhappy.houyuan.activity;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import com.klhappy.houyuan.bean.BaseJsonBean;
import com.klhappy.houyuan.constant.KeyConstant;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.interfaces.CallBackInterModle;
import com.klhappy.houyuan.modle.JiaYuanModle;
import com.klhappy.houyuan.utils.ConfigManager;
import com.klhappy.houyuan.view.AbsActivity;
import com.klhappy.houyuan.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by MrPu on 15/11/20.
 */
public class NameReviseActivity extends AbsActivity implements CallBackInterModle{
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.name_revise)
    EditText name_revise;

    @OnClick(R.id.click_ra)
    public void click_ra(){
        finish();
    }

    @OnClick(R.id.submit)
    public void submit(){
        showDialog("请稍等...");
        modle.setName(name_revise.getText().toString());
    }

    private JiaYuanModle modle;
    private ConfigManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.name_revise);
        ButterKnife.inject(this);
        title.setText("修改昵称");
        modle = new JiaYuanModle(this);
        modle.setCallBackInterModle(this);

        manager = new ConfigManager(this);
        if ("".equals(manager.get(KeyConstant.myname, "")) && null == manager.get(KeyConstant.myname, "")){
            name_revise.setText("");
        }else {
            name_revise.setText(manager.get(KeyConstant.myname, ""));
        }
    }

    @Override
    public void CallBackFromModle(String url, BaseJsonBean o) {
        if (url.equals(UrlConstant.ACCOUNT_URL)){
            if (o.getCode() == 200){
                manager.remove(KeyConstant.myname);

                manager.set(KeyConstant.myname, name_revise.getText().toString());
                showToast(o.getMsg());
                finish();
            }
            closeDialog();
        }
    }
}
